<?php
namespace Home\Controller;
use Think\Controller;
class MessageController extends BaseController {
    public function index(){
    	$m = M("liuyan");
    	$count = $m->count();
        $page = new \Think\Page($count,3);
        $show = $page->show();
        $message = $m->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
    	
    	//dump($arr);
        $this->assign("page",$show);
    	$this->assign("message",$message);
        $this->display();
    }


    public function send(){
    	$m = M("liuyan");
    	$data = $m->create();
    	//dump($data);
    	if($_POST['name'] == '' || $_POST['title'] == '' || $_POST['content'] == ''){
    		$this->error('请您填写完整!');
    	}
    	$color = array("#18A689","#1A7BB9","#21B9BB","#F7A54A","#EC4758","#000000");
    	$number = rand(0,5);
        $data['color']=$color[$number];
    	$data['ctime'] = time();
    	$result = $m->add($data);
 		if($result > 0){

 			$this->success("留言成功!");
 		}else{
 			$this->error("留言失败!");
 		}
    }
}